And, of course, you could also assign the values in the text boxes to variables and then pass them to the procedure:
Private Sub cmdSave_Click()
Dim strFirst As String
Dim strLast As String
strFirst = txtFirst.Text
strLast = txtLast.Text
EmployeeDisplay strFirst, strLast
Call EmployeeDisplay(strFirst, strLast)
End Sub
Parameters in Functions
Functions can also be declared to accept arguments just like procedures. Heres the same EmployeeDisplay routine written now as a function that accepts arguments:
Public Function EmployeeDisplay(strFirst As String, _
strLast As String) As String
Dim strEmp As String
strEmp = "My Last Name is " & strLast
strEmp = strEmp & " and my first name is " & strFirst
EmployeeDisplay = strEmp End Function
Calling Functions with Parameters
To call this function, you still follow all the old rules. Youre just adding the ability to pass in the two parameters.
Private Sub cmdSave_Click()
Dim strName As String
MsgBox EmployeeDisplay("Bill", "Gates")
strName = EmployeeDisplay("Michael", "Gilbert")
MsgBox strName
End Sub